import Mock from 'mockjs';
import { NodeType, RiskLevel } from '../types/attackPath';

// 生成模拟数据
const mockAttackPathData = {
  nodes: [
    { 
      id: '1', 
      name: '192.168.1.1', 
      category: 0, 
      symbolSize: 40,
      value: {
        type: NodeType.IP,
        location: '北京',
        risk: RiskLevel.HIGH,
        firstSeen: '2023-05-10',
        lastSeen: '2023-06-15',
        description: '疑似C2服务器'
      }
    },
    { 
      id: '2', 
      name: 'malware.example.com', 
      category: 1, 
      symbolSize: 35,
      value: {
        type: NodeType.DOMAIN,
        registrar: 'NameCheap Inc',
        created: '2023-01-15',
        expires: '2024-01-15',
        risk: RiskLevel.HIGH,
        description: '恶意域名'
      }
    },
    { 
      id: '3', 
      name: '5f4dcc3b5aa765d61d8327deb882cf99', 
      category: 2, 
      symbolSize: 30,
      value: {
        type: NodeType.FILE,
        fileType: 'exe',
        size: '2.3MB',
        detection: '28/56',
        risk: RiskLevel.HIGH,
        description: 'Trojan.Win32.Downloader'
      }
    },
    { 
      id: '4', 
      name: '10.0.0.15', 
      category: 0, 
      symbolSize: 40,
      value: {
        type: NodeType.IP,
        location: '上海',
        risk: RiskLevel.MEDIUM,
        firstSeen: '2023-05-12',
        lastSeen: '2023-06-10',
        description: '受感染主机'
      }
    },
    { 
      id: '5', 
      name: 'cdn.example.net', 
      category: 1, 
      symbolSize: 35,
      value: {
        type: NodeType.DOMAIN,
        registrar: 'GoDaddy',
        created: '2022-03-22',
        expires: '2025-03-22',
        risk: RiskLevel.LOW,
        description: '疑似被劫持的合法域名'
      }
    },
    { 
      id: '6', 
      name: 'e10adc3949ba59abbe56e057f20f883e', 
      category: 2, 
      symbolSize: 30,
      value: {
        type: NodeType.FILE,
        fileType: 'dll',
        size: '1.1MB',
        detection: '15/56',
        risk: RiskLevel.MEDIUM,
        description: '可疑DLL文件'
      }
    },
    { 
      id: '7', 
      name: '172.16.0.5', 
      category: 0, 
      symbolSize: 40,
      value: {
        type: NodeType.IP,
        location: '广州',
        risk: RiskLevel.LOW,
        firstSeen: '2023-05-20',
        lastSeen: '2023-06-01',
        description: '内网服务器'
      }
    }
  ],
  links: [
    { 
      source: '1', 
      target: '2', 
      value: '解析于',
      lineStyle: { width: 3 }
    },
    { 
      source: '2', 
      target: '3', 
      value: '下载',
      lineStyle: { width: 5 }
    },
    { 
      source: '3', 
      target: '4', 
      value: '感染',
      lineStyle: { width: 4 }
    },
    { 
      source: '4', 
      target: '5', 
      value: '连接',
      lineStyle: { width: 2 }
    },
    { 
      source: '5', 
      target: '6', 
      value: '下载',
      lineStyle: { width: 3 }
    },
    { 
      source: '6', 
      target: '7', 
      value: '横向移动',
      lineStyle: { width: 4 }
    },
    { 
      source: '4', 
      target: '1', 
      value: '回连',
      lineStyle: { width: 5 }
    }
  ]
};

// 模拟接口
Mock.mock(/\/api\/attack-path$/, 'get', () => {
  return {
    code: 200,
    message: '获取成功',
    data: mockAttackPathData
  };
});

// 模拟节点详情接口
Mock.mock(/\/api\/attack-path\/node\/\d+$/, 'get', (options: any) => {
  const id = options.url.match(/\/node\/(\d+)/)[1];
  const node = mockAttackPathData.nodes.find(n => n.id === id);
  
  if (node) {
    return {
      code: 200,
      message: '获取成功',
      data: node
    };
  } else {
    return {
      code: 404,
      message: '节点不存在',
      data: null
    };
  }
});

// 模拟关系详情接口
Mock.mock(/\/api\/attack-path\/relation\/\d+$/, 'get', (options: any) => {
  const id = options.url.match(/\/relation\/(\d+)/)[1];
  const relation = mockAttackPathData.links[parseInt(id) - 1];
  
  if (relation) {
    return {
      code: 200,
      message: '获取成功',
      data: relation
    };
  } else {
    return {
      code: 404,
      message: '关系不存在',
      data: null
    };
  }
});

// 模拟保存接口
Mock.mock(/\/api\/attack-path$/, 'post', () => {
  return {
    code: 200,
    message: '保存成功',
    data: null
  };
});

export default mockAttackPathData; 